module.exports.createOne = (Model, value) => {
  return new Promise(function (resolve, reject) {
    Model.create(value,function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.find = (Model, object,findValue,limit) => {
  return new Promise(function (resolve, reject) {
    Model.find(object,findValue,limit,function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.findAll = (Model) => {
  return new Promise(function (resolve, reject) {
    Model.find({},function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.findOneByid = (Model, object,findValue,) => {
  return new Promise(function (resolve, reject) {
    Model.findOne(object,findValue,function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.updateOne = (Model, object, updateValue) => {
  return new Promise(function (resolve, reject) {
    Model.updateOne( object , updateValue ,
      function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.remove = (Model, object, updateValue) => {
  return new Promise(function (resolve, reject) {
    Model.deleteOne( object , updateValue ,
      function (err, doc) {
      if (!err) {
           resolve(doc)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.count = (Model, object) => {
  return new Promise(function (resolve, reject) {
    Model.countDocuments( object,
      function (err, count) {
      if (!err) {
           resolve(count)
      } else {
           reject(err)
         }
    })
  })
}

module.exports.groupBy = (Model, object) => {
  return new Promise(function (resolve, reject) {
    Model.aggregate( object,
      function (err, count) {
      if (!err) {
           resolve(count)
      } else {
           reject(err)
         }
    })
  })
}





